package com.duneyr.snakes.generate;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Daniel
 */
public class GenRoom {

    Set<GenPosition> perimeter = new HashSet<GenPosition>();
    Set<GenRoom> connectedRooms = new HashSet<GenRoom>();

    public boolean overlaps(GenRoom o) {
        return false;
    }

    public boolean isConnectedTo(GenRoom room) {
    	if(this == room) return true;
        return connectedRooms.contains(room);
    }

    /**
     * Suitable point for a door to a corridor to room r2.
     * Try to choose a point on the perimeter of this room
     * that has a corridor or empty block just outside. 
     * and is roughly in the direction of r2. If only room
     * blocks are found then just grab any perimiter block.
     * (optional) Try to favor bits with corridor outside.
     * @param r2 the room we aim for.
     * @return the position on the perimeter of the room that is
     * suitable for a connection. 
     */
    public GenPosition connectionPoint(GenRoom r2, AbstractGenMap map) {
        // TODO improve
        int n = (int)(Math.random()*perimeter.size());
        return (GenPosition) (perimeter.toArray()[n]);
    }

    public void addPerimeterBlockPosition(GenPosition block) {
        perimeter.add(block);
    }

    public void connectTo(Set<GenRoom> roomsThatConnect) {
        connectedRooms.addAll(roomsThatConnect);
    }
}
